/*xz19Hnz0vyifyMdV+FdCT+5gRzhoVL6K2OdRhxifl6gyRZAWzkTZnUthLT568mwV*/
//**********************
//* 单据联查到固定资产卡片
//**********************
import {cacheTools, ajax } from 'nc-lightapp-front';

import constants from "../../constants";
import { listQueryBackHandler } from "./commonHandler";
import fa from 'fa';
const {fa_utils} = fa;
const {getUrlParamByPrivateUse} = fa_utils.URLParamUtil;
import ampub from 'ampub';
const {commonConst, utils} = ampub;
const {linkQueryConst} = commonConst.CommonKeys;
const {listConst} = utils.listUtils;


//处理其他单据联查卡片到列表态
function linkedQueryByBill(props) {
    // 1 判断是否来源于 预算联查
    let pk_ntbparadimvo = getUrlParamByPrivateUse.call(this, 'pk_ntbparadimvo');
    //判断是否是通过预算联查跳转过来的页面
    if (pk_ntbparadimvo) {
        let param = {
            pagecode: constants.PAGE_CODE.LIST,
            templateid: this.templateid,
            pk_ntbparadimvo
        };
        ajax({
            url: constants.URL.QueryaboutByBudget,
            data: param,
            success: (res) => {
                listQueryBackHandler.success.call(this, props, res, listConst.SETVALUETYPE.default);
            },
            error: (err) => {
                listQueryBackHandler.error(props, err);
            }
        });
    } else {
        // 2 通过联查场景联查
        //获取联查场景
        let scene = props.getUrlParam(linkQueryConst.SCENE);
        if (scene === linkQueryConst.SCENETYPE.linksce) {
            let linkParam = cacheTools.get('fa_facard_linkQuery_param');
            let pks =  linkParam['pk_cards'];
            //删除缓存
            cacheTools.remove('fa_facard_linkQuery_param');
            if(pks && pks.length) {
                let param = {
                    allpks: pks,
                    pagecode: constants.PAGE_CODE.LIST,
                };
                ajax({
                    url: constants.URL.QUERY_LIST_BYPKS_LINKED,
                    data: param,
                    success: (res) => {
                        listQueryBackHandler.success.call(this, props, res, listConst.SETVALUETYPE.default);
                    },
                    error: (err) => {
                        listQueryBackHandler.error(props, err);
                    }
                });
            }
        }
    }
}

//通过凭证联查单据
function linkedQueryByVoucher(props, linkQueryInfo) {
    ajax({
        url: constants.URL.QUERY_LIST_BYPKS_LINKED,
        data: linkQueryInfo,
        success: (res) => {
            listQueryBackHandler.success.call(this, props, res, listConst.SETVALUETYPE.default);
        },
        error: (err) => {
            listQueryBackHandler.error(props, err);
        }
    });
}

export {
    linkedQueryByVoucher,
    linkedQueryByBill,
}


/*xz19Hnz0vyifyMdV+FdCT+5gRzhoVL6K2OdRhxifl6gyRZAWzkTZnUthLT568mwV*/